package com.aaa.book_mall.dao.impl;

import com.aaa.book_mall.dao.AuditDao;
import com.aaa.book_mall.entity.Audit;
import com.aaa.book_mall.util.JDBCUtil;

import java.util.List;
import java.util.Map;

/**
 * fileName:AuditDaoImpl
 * description:
 * author:付亚星
 * createTime:2021/1/20 14:19
 * version:1.0.0
 */
public class AuditDaoImpl implements AuditDao{
    @Override
    public int insertAudit(Audit audit) {
        String sql = "insert into t_audit values(null,?,?,?,?,?,?,?)";
        int update = JDBCUtil.update(sql, audit.getAuditnumber(), audit.getAudit_staffid(), audit.getAudit_staffname(),
                audit.getAudit_number(), audit.getAudit_result(), audit.getAudit_info(), audit.getAudit_date());

        return update;
    }

    @Override
    public List<Map<String, Object>> selectAllAudit(Audit audit) {
        String sql = "select * from t_audit limit ?,?";
        List<Map<String, Object>> maps = JDBCUtil.queryListMap(sql,(audit.getPage()-1)*audit.getLimit(),audit.getLimit());
        return maps;
    }

    /**
     * 查询不通过的记录
     * @param audit
     * @return
     */
    @Override
    public List<Map<String, Object>> selectNoAudit(Audit audit) {
        return null;
    }

    @Override
    public int countAudit() {
        String sql = "select count(*) from t_audit";
        List<List> lists = JDBCUtil.queryList(sql);
        int count=0;
        if(lists.size()>0){
            count=Integer.parseInt(lists.get(0).get(0).toString());
        }
        return count;
    }

    /**
     * 根据id查询audit_number
     * @param id
     * @return
     */
    @Override
    public String getOneAudit(Integer id) {
        String sql = "select audit_number from t_audit where id=?";
        List<List> lists = JDBCUtil.queryList(sql, id);
        String audit_number = null;
        if(lists.size()>0){
            audit_number = lists.get(0).get(0).toString();
        }
        return audit_number;
    }

    @Override
    public int deleteAudit(Integer id) {
        String sql = "delete from t_audit where id=?";
        int update = JDBCUtil.update(sql, id);
        return update;
    }

}
